import request from '@/utils/request'
import Qs from 'qs'
export function list(query) {
  return request({
    method: 'get',
    params: {
      _gp: 'admin.warehouse',
      _mt: 'list',
      ...query
    }
  })
}

export function active(data) {
  return request({
    method: 'post',
    data: Qs.stringify({
      _gp: 'admin.warehouse',
      _mt: 'updateStatus',
      ...data
    })
  })
}

export function create(data) {
  return request({
    method: 'post',
    data: Qs.stringify({
      _gp: 'admin.warehouse',
      _mt: 'create',
      warehouseDO: JSON.stringify(data)
    })
  })
}

export function update(data) {
  return request({
    method: 'post',
    data: Qs.stringify({
      _gp: 'admin.warehouse',
      _mt: 'update',
      warehouseDO: JSON.stringify(data)
    })
  })
}

export function del(data) {
  return request({
    method: 'post',
    data: Qs.stringify({
      _gp: 'admin.warehouse',
      _mt: 'delete',
      ...data
    })
  })
}
export function detail(data) {
  return request({
    method: 'post',
    data: Qs.stringify({
      _gp: 'admin.warehouse',
      _mt: 'detail',
      ...data
    })
  })
}
export function listWareHousesByPara(query) {
  return request(
    {
      method: 'get',
      params: {
        _gp: 'admin.warehouse',
        _mt: 'listWareHousesByPara',
        ...query
      }
    }
  )
}

export function exportSkuSummary(startTime, endTime, storeId, state, stateStr, orderNo, goodsEntryType, skuSearch, pwOrderIdStr) {
  startTime = startTime && startTime !== '' ? startTime : ''
  endTime = endTime && endTime !== '' ? endTime : ''
  state = state || ''
  stateStr = stateStr && stateStr !== '' ? stateStr : ''
  orderNo = orderNo && orderNo !== '' ? orderNo : ''
  skuSearch = skuSearch && skuSearch !== '' ? skuSearch : ''
  storeId = storeId && storeId !== '' ? storeId : ''
  pwOrderIdStr = pwOrderIdStr && pwOrderIdStr !== '' ? pwOrderIdStr : ''
  console.log(startTime, endTime, storeId, state, stateStr, orderNo, goodsEntryType, skuSearch, pwOrderIdStr)
  const exportOrderSummaryHref = process.env.HOST + '/excel/exportSkuSummary'
  const a = document.createElement('a')
  console.log(encodeURI(exportOrderSummaryHref + '?startTime=' + startTime + '&endTime=' + endTime + '&storeId=' + storeId + '&state=' + state + '&stateStr=' + stateStr + '&orderNo=' + orderNo + '&goodEntryType=' + goodsEntryType + '&skuSearch=' + skuSearch + '&pwOrderIdStr=' + pwOrderIdStr))
  a.setAttribute('href', encodeURI(exportOrderSummaryHref + '?startTime=' + startTime + '&endTime=' + endTime + '&storeId=' + storeId + '&state=' + state + '&stateStr=' + stateStr + '&orderNo=' + orderNo + '&goodEntryType=' + goodsEntryType + '&skuSearch=' + skuSearch + '&pwOrderIdStr=' + pwOrderIdStr))
  a.click()
  a.remove()
}
